<?php
$app_codes = '';
$app_root = dirname(dirname(__FILE__)).'/';

$filename = $app_root . 'inc/x.php';
$str = substr(file_get_contents($filename), 5);
$app_codes .= $str;


$filename = $app_root . 'cfg/common.cfg.php';
$cfgStr = substr(file_get_contents($filename), 5);
$app_codes = str_replace(
	'include($app_cfg.\'common.cfg.php\');', 
	$cfgStr, 
	$app_codes
);

$filename = $app_root . 'inc/functions.php';
$cfgStr = substr(file_get_contents($filename), 5);
$app_codes = str_replace(
	'include($app_inc.\'functions.php\');', 
	$cfgStr, 
	$app_codes
);

$classesStr = '';
$app_base = $app_root.'base/';
$filename = $app_base . 'App.class.php';
$classesStr .= substr(file_get_contents($filename), 5);

$filename = $app_base . 'Db.class.php';
$classesStr .= substr(file_get_contents($filename), 5);

$filename = $app_base . 'Model.class.php';
$classesStr .= substr(file_get_contents($filename), 5);

$filename = $app_base . 'Page.class.php';
$classesStr .= substr(file_get_contents($filename), 5);

$filename = $app_base . 'Tpl.class.php';
$classesStr .= substr(file_get_contents($filename), 5);

$app_codes = str_replace('/*include classes here*/', $classesStr, $app_codes);

$app_codes = preg_replace('~/\*[\s\S]+?\*/~', '', $app_codes);
$app_codes = preg_replace("~//[[\s\S]+?\n([\s]*)~", '', $app_codes);
$app_codes = preg_replace("~\r\n[\s]+\r\n~", "\r\n", $app_codes);

$lang = include $app_lang.$lang.'/common.lang.php';
if (is_file($filename = $app_lang.$lang.'/user.lang.php')) {
	$userLang = include $app_lang.$lang.'/user.lang.php';
} else {
	$userLang = array();
}
$lang = $lang + $userLang;
$langStr = '';
foreach ($lang as $k=>$v) {
	if (is_string($v)) {
		$v = addslashes($v);
	}
	$langStr .= '$'.$k.' = \''.$v."';\n";
}

$app_codes = str_replace('L(\'common\', \'user\');', $langStr, $app_codes);

file_put_contents($app_root.'inc/xlite.php', '<?php '.$app_codes);

echo 'ok';